package com.example.mountCard.service.Impl;

import com.example.entity.MonthCard;
import com.example.mountCard.dao.MonthCardMapper;
import com.example.mountCard.service.MonthCardService;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.NumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MonthCardServiceImpl implements MonthCardService {
    @Autowired
    MonthCardMapper monthCardMapper;

    /**
     * 停车场管理-月卡全查
     * @param monthCardCode
     * @return
     */
    @Override
    public CommonResult getMonthCard(String monthCardCode) {
        return CommonResult.ok(MyPageHelper.getPageResult(monthCardMapper.getMonthCard(monthCardCode)));
    }

    /**
     * 停车场管理-月卡删除
     * @param id
     * @return
     */
    @Override
    public int delMonthCard(Integer id) {
        int i = monthCardMapper.delMonthCard(id);
        return i;
    }

    /**
     * 停车场管理-月卡增改
     * @param monthCard
     * @return
     */
    @Override
    public int saveOrUpdateMonth(MonthCard monthCard) {
        int i = 0;
        if(monthCard.getId() == 0){
            monthCard.setCreateTime(new Date());
            monthCard.setUpdateTime(new Date());
            monthCard.setMonthCardDelFlag(0);
            int code = NumUtil.Num();
            String code01 = "NH"+code;
            monthCard.setMonthCardCode(code01);
            i = monthCardMapper.addMonth(monthCard);
        }else {
            monthCard.setUpdateTime(new Date());
            i = monthCardMapper.updateMonth(monthCard);
        }
        return i;
    }
}
